﻿// ====================================================================
//  Texy.net - XML-RPC client for Texy! formatter
//  (c) 2006 Aleš Roubíček - Creative Commons 2.5 License
// --------------------------------------------------------------------
//  version: 1.0 RC2
// ====================================================================

using System;
using System.Configuration;

namespace Rarous.TexyNet.Configuration
{
    /// <summary>
    /// Tag element collection
    /// </summary>
    public class TagElementCollection : ConfigurationElementCollection
    {
        #region Constructors
        /// <summary>
        /// 
        /// </summary>
        public TagElementCollection() { }
        #endregion

        /// <summary>
        /// 
        /// </summary>
        public override ConfigurationElementCollectionType CollectionType
        {
            get { return ConfigurationElementCollectionType.AddRemoveClearMap; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new TagElement();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        protected override Object GetElementKey(ConfigurationElement element)
        {
            return (element as TagElement).Name;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public TagElement this[int index]
        {
            get { return BaseGet(index) as TagElement; }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        new public TagElement this[string name]
        {
            get
            {
                return BaseGet(name) as TagElement;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public int IndexOf(TagElement element)
        {
            return BaseIndexOf(element);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="element"></param>
        public void Add(TagElement element)
        {
            BaseAdd(element);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="element"></param>
        protected override void BaseAdd(ConfigurationElement element)
        {
            BaseAdd(element, false);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="element"></param>
        public void Remove(TagElement element)
        {
            if (BaseIndexOf(element) >= 0)
            {
                BaseRemove(element.Name);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="index"></param>
        public void RemoveAt(int index)
        {
            BaseRemoveAt(index);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        public void Remove(string name)
        {
            BaseRemove(name);
        }

        /// <summary>
        /// 
        /// </summary>
        public void Clear()
        {
            BaseClear();
        }
    }
}
